/*
* Copyright (c) 2010 Michael Collins
*
* This file is part of TerraFirma.
*
* TerraFirma is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TerraFirma is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TerraFirma.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "ent_ref.h"
#include "entity.h"
#include "context.h"

namespace game
{
    ent_ref::ent_ref(const Entity& ent, uint32_t subidx) : ent_type(ent.type()), subtype_idx(subidx)
    {}

    ent_ref::ent_ref(uint32_t type, uint32_t subidx) : ent_type(type), subtype_idx(subidx)
    {}

    Entity& ent_ref::operator*()
    {
        switch (ent_type)
        {
        case PHYSICS:
            return context::Instance().world.physics_entities[subtype_idx];
        case VEHICLE:
            return context::Instance().world.vehicle_entities[subtype_idx];
        case ENTITY:
        default:
            return context::Instance().world.entities[subtype_idx];
        }
    }

    const Entity& ent_ref::operator*() const
    {
        switch (ent_type)
        {
        case PHYSICS:
            return context::Instance().world.physics_entities[subtype_idx];
        case VEHICLE:
            return context::Instance().world.vehicle_entities[subtype_idx];
        case ENTITY:
        default:
            return context::Instance().world.entities[subtype_idx];
        }
    }

}
